package com.beidouin.sensortest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.friendlyarm.AndroidSDK.GPIOEnum;
import com.friendlyarm.AndroidSDK.HardwareControler;

public class RelayActivity extends AppCompatActivity implements View.OnClickListener{

    Button relaybtn;
    TextView relaytxv;
    boolean relaysta;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_relay);
        relaysta=true;
        relaybtn= (Button) findViewById(R.id.Relaybtn);
        relaytxv= (TextView) findViewById(R.id.Relaytxv);
        HardwareControler.exportGPIOPin(73);
        HardwareControler.setGPIODirection(73,GPIOEnum.OUT);
        HardwareControler.setGPIOValue(73,GPIOEnum.LOW);
        relaybtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.Relaybtn:
            {
                relaysta=!relaysta;
                if (relaysta)
                {
                    relaytxv.setText("继电器状态：开");
                    HardwareControler.setGPIOValue(73,GPIOEnum.HIGH);
                }
                else{
                    relaytxv.setText("继电器状态：关");
                    HardwareControler.setGPIOValue(73,GPIOEnum.LOW);
                }
            }
        }
    }
}
